#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <string.h>
#include <errno.h>
#include <sys/un.h>
#include <sys/socket.h>

#define LOG_TAG "mysrv_test"
#include <log/log.h>

#define SOCKET_NAME_TEST  "mysock"


int main(int argc, char *argv[])
{
	int fd = -1;
	int ret = -1;
	
	fd = socket(AF_LOCAL, SOCK_STREAM, 0);
	if(fd < 0){
		ALOGE("socket error: %s", strerror(errno));
		exit(1);
	}

	struct sockaddr_un  srv_addr;
    	srv_addr.sun_family = AF_LOCAL;
    	strlcpy(srv_addr.sun_path, "/dev/socket/mysocket", sizeof(srv_addr.sun_path));
	ret = connect(fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr));
	if(ret < 0){
		ALOGE("connect error: %s", strerror(errno));
		exit(1);
	}

	char content[256];
	snprintf(content, 256, "hello from client pid = %d", getpid());
	ret = write(fd, content, 256);
	if(ret < 0){
		ALOGE("write error: %s", strerror(errno));
		exit(1);
	}

	close(fd);

	return 0;
}

